{% extends "base.html" %}

{% block content %}
<div class="container">
    <h2 class="mb-4">收付款记录</h2>
    
    <div class="card mb-4">
        <div class="card-body">
            <form method="GET" class="row g-3">
                <div class="col-md-3">
                    <input type="text" class="form-control" name="settlement_id" placeholder="结算单号" value="{{ settlement_id }}">
                </div>
                <div class="col-md-3">
                    <select class="form-select" name="payment_method">
                        <option value="">支付方式</option>
                        <option value="cash" {% if payment_method == 'cash' %}selected{% endif %}>现金</option>
                        <option value="bank_transfer" {% if payment_method == 'bank_transfer' %}selected{% endif %}>银行转账</option>
                        <option value="alipay" {% if payment_method == 'alipay' %}selected{% endif %}>支付宝</option>
                        <option value="wechat" {% if payment_method == 'wechat' %}selected{% endif %}>微信支付</option>
                    </select>
                </div>
                <div class="col-md-3">
                    <select class="form-select" name="status">
                        <option value="">状态</option>
                        <option value="pending" {% if status == 'pending' %}selected{% endif %}>处理中</option>
                        <option value="success" {% if status == 'success' %}selected{% endif %}>成功</option>
                        <option value="failed" {% if status == 'failed' %}selected{% endif %}>失败</option>
                    </select>
                </div>
                <div class="col-md-3">
                    <button type="submit" class="btn btn-primary w-100">搜索</button>
                </div>
            </form>
        </div>
    </div>

    <div class="mb-3">
        <a href="{{ url_for('finance.payment_add') }}" class="btn btn-success">
            <i class="fas fa-plus"></i> 新增付款
        </a>
    </div>

    <div class="table-responsive">
        <table class="table table-striped table-hover">
            <thead>
                <tr>
                    <th>付款单号</th>
                    <th>结算单号</th>
                    <th>金额</th>
                    <th>支付方式</th>
                    <th>支付时间</th>
                    <th>状态</th>
                    <th>交易流水号</th>
                    <th>备注</th>
                </tr>
            </thead>
            <tbody>
                {% for payment in payments %}
                <tr>
                    <td>{{ payment.payment_no }}</td>
                    <td>{{ payment.settlement_id }}</td>
                    <td>¥{{ "%.2f"|format(payment.amount|float) }}</td>
                    <td>
                        {% if payment.payment_method == 'cash' %}
                            现金
                        {% elif payment.payment_method == 'bank_transfer' %}
                            银行转账
                        {% elif payment.payment_method == 'alipay' %}
                            支付宝
                        {% elif payment.payment_method == 'wechat' %}
                            微信支付
                        {% endif %}
                    </td>
                    <td>{{ payment.payment_time.strftime('%Y-%m-%d %H:%M') }}</td>
                    <td>
                        {% if payment.status == 'pending' %}
                            <span class="badge bg-warning">处理中</span>
                        {% elif payment.status == 'success' %}
                            <span class="badge bg-success">成功</span>
                        {% else %}
                            <span class="badge bg-danger">失败</span>
                        {% endif %}
                    </td>
                    <td>{{ payment.transaction_id or '-' }}</td>
                    <td>{{ payment.notes or '-' }}</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>

    {% if pagination.pages > 1 %}
    <nav aria-label="Page navigation">
        <ul class="pagination justify-content-center">
            {% for page in pagination.iter_pages() %}
                {% if page %}
                    <li class="page-item {% if page == pagination.page %}active{% endif %}">
                        <a class="page-link" href="{{ url_for('finance.payment_list', page=page, settlement_id=settlement_id, payment_method=payment_method, status=status) }}">{{ page }}</a>
                    </li>
                {% else %}
                    <li class="page-item disabled"><span class="page-link">...</span></li>
                {% endif %}
            {% endfor %}
        </ul>
    </nav>
    {% endif %}
</div>
{% endblock %} 